package com.xcity.game.achievement.helper;

import com.xcity.game.achievement.Achievement;
import com.xcity.game.achievement.Achievement.State;
import com.xcity.game.achievement.AchievementHelper;
import com.xcity.game.achievement.AchievementTemplate;

/**
 * 成就类型：人物等级<br/>
 * 1个参数：①人物等级
 * @author yang.li
 *
 */
public class LevelUpHelper implements AchievementHelper {

	@Override
	public boolean update(Achievement refer, int... vals) {
		return isFinished(refer);
	}

	@Override
	public boolean isFinished(Achievement refer) {
		if (refer.getState() == State.INITED
				&& refer.getVm().getOwner().getLevel() >= obtainLevel(refer.getTemplate())) {
			refer.setState(State.FINISHED);
			return true;
		}
		return false;
	}
	
//	static int obtainLevel(int... vals) {
//		return vals != null && vals.length > 0 ? vals[0] : 0;
//	}
//	
	static int obtainLevel(AchievementTemplate template) {
		return (int) template.getCondition(0);
	}
	
}
